class Operation:
    def __init__(self):
        self.id = None
        self.delay_time = 1.0
        self.help = f"\n《操作手册 v0.1》：" \
                    f"按下<Tab>键可以自动生成[n]编号和type,填写type后，再次按下<Tab>，" \
                    f"可以生成对应的操作" \
                    f"\n\t[0] # 从0开始，代表操作的顺序" \
                    f"\n\ttype = Click  # 有三种操作,Click点击、Drag拖拽、Input输入文本" \
                    f"\n\tdelay_time = 1.0 # 是一个浮点数，单位为秒，代表每个操作执行后的延迟" \
                    f"\n\ttranslate = 0,0 # 坐标，为0,0时代表识别特征的中心位置" \
                    f"\n\ttranslate_drag = 0,0 # 拖拽到的坐标" \
                    f"\n\ttext = 你好[text] # 键盘模拟输入的文本[text/http]，也可以这样：" \
                    f"\n\t(text = 127.0.0.1:8080/name[http] #以动态获取输入文本)"

    def set(self, operations):
        """根据字典转换为object"""

    def set_help(self):
        """设置帮助文档"""

    def to_string(self):
        return '\n'.join(['%s:%s' % item for item in self.__dict__.items()])

    def get_help(self):
        return self.help


class Click(Operation):
    def __init__(self):
        super().__init__()
        self.translate = ""

    def set(self, operations):
        self.id = operations["id"]
        self.translate = operations["translate"]
        self.delay_time = operations["delay_time"]
        self.set_help()
        return self

    def set_help(self):
        self.help = f"\n[{self.id}]" \
                    f"\ntype = Click # 点击操作" \
                    f"\ndelay_time = {self.delay_time} # 点击操作后会延迟{self.delay_time}秒" \
                    f"\ntranslate = {self.translate} # 点击的坐标，为0,0时代表识别特征的中心位置"


class Drag(Operation):
    def __init__(self):
        super().__init__()
        self.translate = ""
        self.translate_drag = ""

    def set(self, operations):
        self.id = operations["id"]
        self.translate = operations["translate"]
        self.translate_drag = operations["translate_drag"]
        self.delay_time = operations["delay_time"]
        self.set_help()
        return self

    def set_help(self):
        self.help = f"\n[{self.id}]" \
                    f"\ntype = Drag # 拖拽操作" \
                    f"\ndelay_time = {self.delay_time} # 点击操作后会延迟{self.delay_time}秒" \
                    f"\ntranslate = {self.translate} # 拖拽前的坐标，为0,0时代表识别特征的中心位置" \
                    f"\ntranslate_drag = {self.translate_drag} # 拖拽到的坐标"


class Input(Operation):
    def __init__(self):
        super().__init__()
        self.text = ""
        self.type = ""

    def set(self, operations):
        self.id = operations["id"]
        text = operations["text"]
        self.delay_time = operations["delay_time"]
        self.text = text.split("[")[0]
        self.type = text.split("[")[1].split("]")[0]
        if self.type != "text" and self.type != "http":
            self.type = "text"
        self.set_help()
        return self

    def set_help(self):
        self.help = f"\n[{self.id}]" \
                    f"\ntype = Input # 输入文本操作" \
                    f"\ndelay_time = {self.delay_time} # 点击操作后会延迟{self.delay_time}秒" \
                    f"\ntext = {self.text}[{self.type}] # 输入字符串：{self.text}"